package top.shiyiri.shops.controller;

import com.alibaba.fastjson.JSONObject;
import top.shiyiri.shops.bean.ProHotShopTop10;
import top.shiyiri.shops.service.ProHotShopTop10Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Aunean
 * @date 2021/12/27
 */

@Controller
public class ProHotShopTop10Controller {

    @Autowired
    private ProHotShopTop10Service service;

    @ResponseBody
    @RequestMapping("/proHotShopTop10ByPage")
    public String proHotShopTop10ByPage(int page, HttpSession session) {
        List<ProHotShopTop10> list = service.proHotShopTop10ByPage(page, 5);

        int lines = service.totalLines();

        int pages = lines % 5 == 0? lines / 5: lines / 5 + 1;

        session.setAttribute("pages", pages);
        session.setAttribute("page", page);

        return JSONObject.toJSONString(list);
    }

    @RequestMapping("/getProHotShopTop10Pages")
    @ResponseBody
    public Integer getProHotShopTop10Pages(HttpSession session) {

        return (Integer) session.getAttribute("pages");
    }

    @ResponseBody
    @RequestMapping("/proHotShopTop10")
    public String proHotShopTop10() {
        List<ProHotShopTop10> list = service.proHotShopTop10();


        return JSONObject.toJSONString(list);
    }
}
